<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('colse')"
      @confirm="onConfirm"
    />
  </div>
</template>
<script>
import { upUserDate } from "../../api/user"
export default {
    props:{
        value:{
            type:String,
            required:true
        }
    },
  data() {
    return {
      minDate: new Date(1999, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(this.value),
    };
  },
  methods:{
      async onConfirm(){
          this.$toast.loading({
                message:'保存中',
                forbidClick:true
            })
            try{
                const data = `${this.currentDate.getFullYear()}-${this.currentDate.getMonth()+1}-${this.currentDate.getDate()}`
                 await upUserDate({
                    birthday:data

                })
                // console.log(data)
                this.$toast.success('成功');
                this.$emit('input',data)
                this.$emit('colse')
                // console.log(this.value)

            }catch (err){
                if (err && err.response && err.response.status == 409){
                    this.$toast.fail('昵称已存在')

                }

            }
      }
  }
};
</script>
<style scoped>
</style>